/** 
* Adapter for displaying list of comments in item view.
*/

package edu.washington.cs.labspecimentransport.adapters;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import edu.washington.cs.labspecimentransport.R;
import edu.washington.cs.labspecimentransport.dataobjects.Comment;

public class CommentsViewAdapter extends BaseAdapter {
	private Context ctx;
	private List<String> commentAuthor;
	private List<Comment> commentList;
	
	public CommentsViewAdapter(Context ctx, List<Comment> commentList, List<String> commentAuthor) {
		this.ctx = ctx;
		this.commentAuthor = commentAuthor;
		this.commentList = commentList;
	}
	
	public int getCount() {
		return commentList.size();
	}

	public Comment getItem(int position) {
		return commentList.get(position);
	}

	public long getItemId(int position) {
		return commentList.indexOf(this.getItem(position));
	}

	public View getView(int position, View view, ViewGroup parent) {
		Comment c = this.getItem(position);
		LinearLayout itemLayout = (LinearLayout) 
			LayoutInflater.from(ctx).inflate(R.layout.item_comment_single, parent, false);
		
		TextView comment_author = (TextView) itemLayout.findViewById(R.id.comment_author);
		comment_author.setText(commentAuthor.get(position));
		
		TextView comment_text = (TextView) itemLayout.findViewById(R.id.comment_text);
		comment_text.setText(c.getText());
		
		return itemLayout;
	}		

}
